<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/25
 * Time: 16:36
 */
namespace app\common\model;

use think\Model;

class Company extends Model
{
    protected $createTime = 'add_time';

    /**
     * 获取公司id
     * @return int
     */
    public static function get_company_id()
    {
        static $company_id = null;
        if ( $company_id !== null ) return $company_id;

        $subdomain = Setting::get_subdomain();
        if ($subdomain) {
            $company_id = OpenCard::get_company_id_by_domain($subdomain);
        }

        if (!$company_id) {
            if (isset($_SESSION['company_id']) && $_SESSION['company_id']) {
                $company_id = $_SESSION['company_id'];
            } else {
                $company_id = User::get_user_company_id();
            }
        }

        return isset($company_id) ? $company_id : 0 ;
    }

}